'use strict';

let Koa = require('koa');
let router = require('koa-router')();
let bodyparser = require('koa-bodyparser');

let routes = require('./routes.js');

let app = new Koa;
app.use(bodyparser());
app.use(router.routes());

for (let r in routes) {
    console.log(r);
    console.log(routes[r]);
    let type = routes[r][0];
    if (type === 'get') {
        router.get(r, routes[r][1]);
    } else {
        router.post(r, routes[r][1]);
    }
}

let port = 3000;
app.listen(port);
console.log(`http://localhost:${port}`);
